﻿using System;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using UDS.Entity;

namespace UDS.WebApp.SubModule
{
    public partial class CatalogPage : CFPageBase
    {
        protected override void OnInit(EventArgs e)
        {
            // Disable ViewState
            EnableViewState = false;
            dgCatalog.EnableViewState = false;

            // Bind data for the DataGrid
            dgCatalog.DataSource = CommonFile.GetCatalogs();
            dgCatalog.DataBind();
            dgCatalog.ItemCommand += new DataGridCommandEventHandler(OnDGCatalog_ItemCommand);

            base.OnInit(e);
        }

        private void OnDGCatalog_ItemCommand(object source, DataGridCommandEventArgs e)
        {
            if (e.CommandName == "Delete" && e.CommandArgument != null)
            {
                if (!CommonFile.DeleteCatalog(int.Parse(e.CommandArgument.ToString())))
                {
                    SiteContext.Current.Alert("不能删除正在使用中的分类。");
                }

                // Re-bind data
                dgCatalog.DataSource = CommonFile.GetCatalogs();
                dgCatalog.DataBind();
            }
        }
    }
}
